package com.an.pay.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.time.Instant;
import java.util.Date;

@Configuration
@MapperScan("com.an.pay.mapper")
@EnableTransactionManagement //启用事务管理
public class MyBatisPlusConfig implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", Date.class, Date.from(Instant.now()));
        this.strictUpdateFill(metaObject, "updateTime", Date.class, Date.from(Instant.now()));
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", Date.class, Date.from(Instant.now()));
    }
}
